home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / essent / FIXES / CSeries.exe / issue98 / CPROG2.CPP < prev   
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.4 KB  |  54 lines

  1. /* PROGRAM CPROG2.CPP - Ctrl+F9 compiles and runs it */
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6.     /*--------------------------------------------------------------+
  7.     | Definition of a function called pause()                       |
  8.     | Pause() prints "Press a key to continue" then waits for a key |
  9.     | to be pressed. The voids are explained in the article.        |
  10.     +--------------------------------------------------------------*/
  11. void pause(void)
  12. {
  13.     printf("\nPress a key to continue...\n");
  14.     while( kbhit() == 0 )
  15.         ;
  16.     getch();
  17. }
  18.     /*-------------------------------------------------------------+ 
  19.     | Note to experienced C/C++ programmers: yes, I know about     |
  20.     | while( !kbhit() ); and (void)getch(); - please don't         |
  21.     | write in. These programs are only illustrative, not part of  |
  22.     | a real project. They have to be clear and explainable within |
  23.     | the scope of the article.                                    |
  24.     +-------------------------------------------------------------*/
  25.  
  26.     /*------------------------------------------------------------+
  27.     | Program execution starts here in the function called main() |
  28.     +------------------------------------------------------------*/
  29. main()
  30. {
  31.  
  32.     clrscr(); // Clears the screen. Header file is CONIO.H
  33.  
  34.     printf("I'm about to call the function Pause()\n");
  35.  
  36.     pause();
  37.     /*------------------------------------------------------------+
  38.     | Once Pause() has been defined, it can be used like a new    |
  39.     | command, although function calls are not commands as such - |
  40.     | no function is part of the of the C++ language although the |
  41.     | behaviour of the common ones have been formally defined by  |
  42.     | by the American National Standards Institute (ANSI).        |
  43.     +------------------------------------------------------------*/
  44.  
  45.     printf("\nDone it. Now let's do it again.\n");
  46.     pause();
  47. }
  48.     /*---------------------------------------------------------------------+
  49.     | Program execution still ends here. Other functions only get executed |
  50.     | if called from Main(), or called from a function that itself is      |
  51.     | called from Main(), or called from a function that is called from    |
  52.     | a function that is called from... etc etc                            |
  53.     +---------------------------------------------------------------------*/
  54.